package cn.yj.core.business.controller;

import cn.yj.cgs.dba.entity.vo.ArticleVo;
import cn.yj.admin.frame.AbstractController;
import cn.yj.syslog.common.LogType;
import cn.yj.syslog.common.OperateLog;
import cn.yj.core.business.service.ArticleService;
import cn.yj.entity.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Map;

/**
 * @author 永健
 * @since 2021-06-09 15:16
 */
@RequestMapping("/article")
@RestController
public class ArticleController extends AbstractController<ArticleVo> {

    @Resource
    private ArticleService articleService;

    @Override
    @GetMapping("/pageList")
    @RequiresPermissions("article:list")
    public R pageList(@RequestParam Map<String, Object> params) {
        return success(articleService.pageList(params, page()));
    }


    /**
     * 更新审核状态
     * @param body - status productNo
     * @return
     */
    @PutMapping("/update/auditStatus")
    @RequiresPermissions("article:update:status")
    @OperateLog(describe = "物品审核",type = LogType.UPDATE)
    public R updateStatus(@RequestBody Map<String, Object> body){
        return result(articleService.updateStatus(body));
    }


    @DeleteMapping("/delete/{ids}")
    @OperateLog(describe = "删除文章",type = LogType.DELETE)
    @RequiresPermissions("product:del")
    public R deleteProduct(@PathVariable("ids") Integer[] ids) {
        return result(articleService.removeByIds(Arrays.asList(ids)));
    }
}
